home *** CD-ROM | disk | FTP | other *** search
- /*
- * Aliens -- an animated video game
- * the original version is from
- * Fall 1979 Cambridge Jude Miller
- *
- * Score keeping modified by Rob Cohen, BTL, June 1980.
- *
- * Concept of levels introduced, bugs fixed, point penalties added
- * by Alex Podlecki, WECo, 81-82.
- */
-
- #include <pwd.h>
- #include <termio.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <ctype.h>
-
- /* defines */
-
- #define SCOREFILE "/usr/games/lib/aliens.hscores"
- #define LOGFILE "/usr/games/lib/aliens.log"
- #define LEFT ','
- #define LLEFT 'z'
- #define RIGHT '/'
- #define LRIGHT 'c'
- #define HALT '.'
- #define LHALT 'x'
- #define FIRE ' '
- #define DELETE '\177'
- #define ABORT '\34'
- #define QUIT 'q'
- #define PAUSE '\23'
- #define QQUIT '\3'
- #define GAME1 '1'
- #define GAME2 '2'
- #define GAME3 '3'
- #define GAME4 '4'
- #define GAME5 '5'
- #define GAME6 '6'
- #define BOMB_MAX 10
- #define BOMB_ROW 20
- #define MINCOL 1
- #define SCORESIZE (sizeof (scorsave))
- #define HP2621 1
- #define ADM3 2
- #define VT100 3
- #define TTY4424 4
- #define Z19 5
- #define OVERUN 10
- #define DEATH 25
-
- /* global variables */
-
- int scores = 0,bases,game;
- int i,j,danger,max_danger;
- int flip,flop,left,al_num,b;
- int al_cnt, bmb_cnt=0, bmb_max, spread;
- int slow = 0;
- int term_type = 0, level = 0;
- int scorefile;
- char combuf[2];
- int ttyin;
- char *ttydev;
- struct termio ttyorig,ttyjunk;
- extern char *ttyname();
- long timein;
- int barrinit[4][81] = {
- {0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,
- 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,
- 0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,
- 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,
- 0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,
- 0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,
- 0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,
- 0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,
- 0,0,0,0,0,0,0,0}
- };
- int barr[4][81];
- struct
- {
- int row;
- int col;
- }
- al[55];
- struct {
- int row;
- int col;
- int vel;
- } bas;
- struct {
- int row;
- int col;
- } bem;
- struct {
- int row;
- int col;
- }bmb[BOMB_MAX];
- struct {
- int val;
- int col;
- int vel;
- }shp;
- struct {
- long hscr;
- short hid;
- long sscr;
- short sid;
- } scorsave[6] = {
- {0,0,0,0},
- {0,0,0,0},
- {0,0,0,0},
- {0,0,0,0},
- {0,0,0,0},
- {0,0,0,0}
- };
-
- /*
- * main -- scheduler and main entry point for aliens
- */
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- char *getenv();
-
- ttydev = getenv("TERM");
- if (ttydev)
- {
- switch (*ttydev)
- {
- case '2':
- term_type = HP2621;
- break;
- case 'a':
- term_type = ADM3;
- break;
- case 'v':
- term_type = VT100;
- break;
- case '4':
- term_type = TTY4424;
- break;
- case 'z':
- case 'g':
- term_type = Z19;
- break;
- }
- }
- for ( i = 1; i < argc; i++ )
- switch ( argv[i][0] )
- {
- case '-':
- switch ( argv[i][1] )
- {
- case 'T':
- switch ( argv[i][2] )
- {
- case '2':
- term_type = HP2621;
- break;
- case 'a':
- term_type = ADM3;
- break;
- case 'v':
- term_type = VT100;
- break;
- case '4':
- term_type = TTY4424;
- break;
- case 'z':
- case 'g':
- term_type = Z19;
- break;
- default:
- usage();
- break;
- }
- break;
- case 'l':
- if ( isdigit(level=argv[i][2]) == 0 )
- usage();
- level -= '0';
- break;
- case 's':
- alhs();
- break;
- default:
- usage();
- break;
- }
- break;
- default:
- usage();
- break;
- }
- if ( term_type == 0 )
- usage();
- init();
- while (1)
- {
- tabl();
- while (1)
- {
- poll();
- beam();
- beam();
- beam();
- base();
- bomb();
- ship();
- if ( game != 4 ) alien();
- if ( game == 2 ) alien();
- alien();
- if ((al_cnt == 0) && (bmb_cnt == 0)) break;
- };
- gauntlet();
- };
- }
-
- /*
- * usage -- error message for incorrect usage
- */
-
- usage()
- {
- (void) printf(" Usage: aliens -Tname -ldigit -s\n");
- (void) printf(" where name is one of the following terminal types\n");
- (void) printf(" 2621 adm3 vt100 z19 4424\n");
- (void) printf(" digit is the level of difficulty from 0 to 9\n");
- (void) printf(" level 0 is the easiest and is the default\n");
- (void) printf(" and the s option only lists high scores\n");
- exit(1);
- }
-
- /*
- * init -- does global initialization
- */
-
- init()
- {
- extern long time();
- int btemp;
-
- (void) time(&timein); /* get start time */
- srand((unsigned) timein); /* start rand randomly */
-
- /* do terminal dependent initialization */
-
- switch ( term_type )
- {
- case VT100:
- (void) printf("\033<"); /* set ANSI mode */
- break;
- case TTY4424:
- (void) printf("\033[20l"); /* set line feed only for new line */
- break;
- default:
- break;
- }
-
- /* setup raw mode, no echo */
-
- if ((ttydev = ttyname(0)) == NULL) {
- (void) printf("Cannot find terminal\n");
- exit(-1);
- }
- if ((ttyin = open(ttydev,O_RDWR|O_NDELAY)) == -1) {
- (void) printf("Cannot open %s\n",ttydev);
- exit(-1);
- }
- (void) ioctl(ttyin,TCGETA,&ttyorig);
- ttyjunk = ttyorig;
- ttyjunk.c_lflag &= ~(ICANON|ECHO|ISIG);
- ttyjunk.c_oflag &= ~ONLCR;
- ttyjunk.c_iflag &= ~IXON;
- ttyjunk.c_cc[VMIN] = 1;
- ttyjunk.c_cc[VTIME] = 1;
- btemp = ttyjunk.c_cflag & CBAUD;
-
- /* determine low speed terminal penalty factor */
-
- if ( btemp <= B4800 ) slow++;
- if ( btemp <= B2400 ) slow++;
- if ( btemp <= B1200 ) slow++;
-
- (void) ioctl(ttyin,TCSETAW,&ttyjunk);
-
- /* new game starts here */
-
- game = 0;
- instruct();
- while (game==0) poll();
- scores = 0;
- bases = 3;
- max_danger = 22;
- return;
- };
-
- /*
- * instructions -- print out instructions
- */
-
- instruct() {
- clr();
- pos(0,0);
- (void) printf("Attention: Alien invasion in progress!\15\n\n");
- (void) printf(" Type: <,> to move the laser base left\15\n");
- (void) printf(" <z> as above, for lefties\15\n");
- (void) printf(" <.> to halt the laser base\15\n");
- (void) printf(" <x> for lefties\15\n");
- (void) printf(" </> to move the laser base right\15\n");
- (void) printf(" <c> for lefties\15\n");
- (void) printf(" <space> to fire a laser beam\15\n\n");
- (void) printf(" <1> to play \"Bloodbath\"\15\n");
- (void) printf(" <2> to play \"We come in peace\"\15\n");
- (void) printf(" <3> to play \"The Aliens strike back\"\15\n");
- (void) printf(" <4> to play \"Invisible Alien Weasels\"\15\n");
- (void) printf(" <5> to play \"Klinker\"\15\n");
- (void) printf(" <6> to play \"The Black Hole\"\15\n");
- (void) printf(" <q> to quit\15\n\n");
- return;
- }
-
- /*
- * tabl -- tableau draws the starting game tableau.
- */
-
- tabl()
- {
- clr();
- pos(0,0);
- (void) printf("Level:%2d ",level);
- (void) printf("Score: %-5d ",scores);
- switch (game) {
- case 1:
- (void) printf(" B L O O D B A T H ");
- break;
- case 2:
- (void) printf(" W E C O M E I N P E A C E ! ");
- break;
- case 3:
- (void) printf("T H E A L I E N S S T R I K E B A C K !");
- break;
- case 4:
- (void) printf("I N V I S I B L E A L I E N W E A S E L S !");
- break;
- case 5:
- (void) printf(" K L I N K E R ");
- break;
- case 6:
- (void) printf(" T H E B L A C K H O L E ! ");
- break;
- }
- pos(0,70);
- if ( game >= 3 ) (void) printf("Bases: %d",bases);
-
- /* initialize alien co-ords, display */
-
- al_cnt = 55;
- danger = level + 11;
- if ( danger > max_danger ) danger = max_danger;
- bmb_max = level + 5;
- if ( bmb_max > BOMB_MAX ) bmb_max = BOMB_MAX;
- spread = level/2;
- for (j=0;j<=4;j++)
- {
- pos(danger-(2*j),0);
- for (i=0;i<=10;i++)
- {
- ds_obj(((i+j)&1)+(2*(j/2)));
- (void) printf(" ");
- al[(11*j)+i].row = danger - (2*j);
- al[(11*j)+i].col = (6*i);
- };
- };
- al_num = 54;
- flip = 0;
- flop = 0;
- left = 0;
-
- /* initialize laser base position and velocity */
-
- bas.row = 23;
- bas.col = 72;
- if ( rand() < 10000 ) bas.col = 1;
- bas.vel = 0;
- bem.row = 0;
- if ( game < 6 )
- {
- pos(bas.row,bas.col);
- ds_obj(7);
- }
-
- /* initialize bomb arrays (row = 0 implies empty) */
-
- for (i=0;i<bmb_max;i++) bmb[i].row = 0;
- b = 0;
- bmb_cnt = 0;
-
- /* initialize barricades */
-
- for (i=0;i<=3;i++) {
- pos(i+19,0);
- for (j=0;j<80;j++)
- if (barr[i][j]=barrinit[i][j])
- ds_obj(8);
- else (void) printf(" ");
- }
-
- /* initialize mystery ships */
-
- shp.vel = 0;
- return;
- };
-
- /*
- * poll -- read input characters and set global flags
- */
-
- poll() {
- int pausing;
- extern unsigned sleep();
-
- pausing = 0;
- (void) ioctl(ttyin, TCSBRK, 1);
- if (game==1) {
- if (bas.col>=(72-level)) bas.vel = -1;
- if (bas.col<=1) bas.vel = 1;
- }
- while ( read(ttyin,combuf,1) != 0 )
- {
- switch (combuf[0]&0177) { /* do case char */
- case LLEFT: ;
- case LEFT: if (game==1) break;
- bas.vel = -1;
- break;
- case LRIGHT: ;
- case RIGHT: if (game==1) break;
- bas.vel = 1;
- break;
- case LHALT: ;
- case HALT: if (game==1) break;
- bas.vel = 0;
- break;
- case FIRE: if (bem.row==0) bem.row = 22;
- break;
- case DELETE: over();
- break;
- case ABORT: over();
- break;
- case QUIT: over();
- break;
- case PAUSE: pausing = 1;
- break;
- case QQUIT: clr();
- (void) ioctl(ttyin,TCSETAF,&ttyorig);
- exit(0);
- break;
- case GAME1: if (game!=0) break;
- game = 1;
- break;
- case GAME2: if (game!=0) break;
- game = 2;
- break;
- case GAME3: if (game!=0) break;
- game = 3;
- break;
- case GAME4: if (game!=0) break;
- game = 4;
- break;
- case GAME5: if (game!=0) break;
- game = 5;
- break;
- case GAME6: if (game!=0) break;
- game = 6;
- break;
- }
- }
- if ( pausing == 1 ) (void) sleep(1);
- return;
- }
-
- /*
- * pos -- positions cursor to a display position. Row 0 is top-of-screen
- * row 23 is bottom-of-screen. The leftmost column is 0; the rightmost
- * is 79.
- */
-
- pos(row,col)
- int row,col;
- {
- switch ( term_type )
- {
- case VT100:
- case TTY4424:
- (void) printf("\033[%d;%dH",row+1,col+1);
- break;
- case ADM3:
- (void) printf("\033=%c%c", row + ' ', col + ' ');
- break;
- case HP2621:
- (void) printf("\033&a%dy%dC",row,col);
- break;
- case Z19:
- (void) printf("\033Y%c%c", row + ' ', col + ' ');
- };
- return;
- };
-
- /*
- * clr -- issues an escape sequence to clear the display
- */
-
- clr()
- {
- extern unsigned sleep();
-
- switch ( term_type )
- {
- case VT100:
- (void) printf("\033[2J\033[H");
- break;
- case ADM3:
- (void) printf("\032");
- break;
- case HP2621:
- (void) printf("\033h\033J");
- break;
- case Z19:
- (void) printf("\033H\033J");
- break;
- case TTY4424:
- (void) printf("\033[H\033J");
- break;
- };
- (void) sleep(1);
- return;
- };
-
- /*
- * ds_obj -- display an object
- */
-
- ds_obj(class)
- int class;
- {
- if ((game>=4)&&(class>=0)&&(class<=5)) class = 6;
- switch (class)
- {
- case 0:
- switch ( term_type )
- {
- case VT100:
- (void) printf(" \033[7mOXO\033[0m ");
- break;
- default:
- (void) printf(" OXO ");
- break;
- };
- break;
- case 1:
- switch ( term_type )
- {
- case VT100:
- (void) printf(" \033[7mXOX\033[0m ");
- break;
- default:
- (void) printf(" XOX ");
- break;
- };
- break;
- case 2:
- switch ( term_type )
- {
- case VT100:
- (void) printf(" \033[7m\\o/\033[0m ");
- break;
- default:
- (void) printf(" \\o/ ");
- break;
- };
- break;
- case 3:
- switch ( term_type )
- {
- case VT100:
- (void) printf(" \033[7m/o\\\033[0m ");
- break;
- default:
- (void) printf(" /o\\ ");
- break;
- };
- break;
- case 4:
- switch ( term_type )
- {
- case VT100:
- (void) printf(" \033[7m\"M\"\033[0m ");
- break;
- default:
- (void) printf(" \"M\" ");
- break;
- };
- break;
- case 5:
- switch ( term_type )
- {
- case VT100:
- (void) printf(" \033[7mwMw\033[0m ");
- break;
- default:
- (void) printf(" wMw ");
- break;
- };
- break;
- case 6:
- (void) printf(" ");
- break;
- case 7:
- (void) printf(" xx|xx ");
- break;
- case 8:
- if ( game >= 5 ) break;
- switch ( term_type )
- {
- case VT100:
- (void) printf("\033[7m \033[0m");
- break;
- default:
- (void) printf("#");
- break;
- }
- break;
- };
- return;
- };
-
- /*
- * base -- move the laser base left or right
- */
-
- base()
- {
- if ( bas.vel == 0 ) return;
- bas.col += bas.vel;
- if ( bas.col < 1 )
- {
- bas.col = 1;
- bas.vel = 0;
- }
- else if ( bas.col > 72 )
- {
- bas.col = 72;
- bas.vel = 0;
- }
- if ( game < 6 )
- {
- pos(bas.row,bas.col);
- ds_obj(7);
- }
- };
-
- /*
- * beam -- activate or advance the laser beam if required
- */
-
- beam()
- {
- int points;
-
- /* display beam */
-
- switch (bem.row) {
- case 23:
- case 0: return;
- case 21: pos(21,bem.col);
- (void) printf("|");
- break;
- case 22:bem.col = bas.col + 3;
- pos(22,bem.col);
- (void) printf("|");
- break;
- default: pos(bem.row,bem.col);
- (void) printf("|\10\12\12 ");
- break;
- }
-
- /* check for contact with an alien */
-
- for (i=0;i<55;i++) {
- if ((al[i].row==bem.row)&&((al[i].col+1)<=bem.col)
- &&((al[i].col+3)>=bem.col)) {
-
- /* contact! */
-
- points = 1 + (i/22) + (level*(i/11));
- if (game != 1) points = points - slow;
- if (points <= 1) points = 1;
- scores += points;
- scoreit();
- pos(bem.row+1,bem.col);
- (void) printf(" ");
- if (game >= 4) (void) printf("\07");
- pos(al[i].row,al[i].col);
- ds_obj(6); /* erase beam and alien */
- bem.row=0;
- al[i].row=0; /* clear beam and alien state */
- al_cnt--;
- return;
- }
- }
-
- /* check for contact with a bomb */
-
- for (i=0;i<bmb_max;i++) {
- if ((bem.row==bmb[i].row)&&(bem.col==bmb[i].col)) {
- pos(bem.row,bem.col);
- (void) printf(" \10\12 ");
- bem.row = 0;
- bmb_cnt--;
- bmb[i].row = 0;
- return;
- }
- }
-
- /* check for contact with a barricade */
-
- if ((bem.row>=19)&&(bem.row<=22)&&(barr[bem.row-19][bem.col]))
- {
- pos(bem.row,bem.col);
- if ( game == 2 )
- ds_obj(8);
- else
- {
- barr[bem.row-19][bem.col] = 0;
- (void) printf(" ");
- }
- if ( bem.row != 22 )
- (void) printf("\10\12 ");
- bem.row = 0;
- return;
- }
-
- /* check for contact with a mystery ship */
-
- if ((shp.vel!=0)&&(bem.row==1)&&(bem.col>(i=shp.col-shp.vel))&&(bem.col<i+7)) {
-
- /* contact! */
-
- pos(1,i);
- (void) printf(" <BOOM!> \07");
- pos(1,i);
- (void) printf(" "); /* erase ship */
- shp.vel = 0;
- scores += shp.val/3;
- scoreit();
- pos(2,bem.col);
- (void) printf(" ");
- bem.row = 0;
- return;
- }
-
- /* check for air ball */
-
- if ((--bem.row)==0) {
- pos(1,bem.col);
- (void) printf(" \10\12 ");
- scores -= (level + 1);
- scoreit();
- }
- return;
- };
-
- /*
- * bomb -- advance all active bombs
- */
-
- bomb() {
- extern unsigned sleep();
-
- for ( b=0; b<bmb_max; b++)
- {
- if ( bmb_cnt == 0 ) return;
- if ( bmb[b].row == 0 ) continue;
-
- /* advance bomb, check for hit and display */
-
- bmb[b].row++;
- if (bmb[b].row==23) {
- if ((bmb[b].col>bas.col)&&
- (bmb[b].col<=(bas.col+5))) {
-
- /* the base is hit! */
-
- if ( game > 5 )
- {
- pos(bas.row,bas.col);
- ds_obj(7);
- }
- bases--;
- pos(0,70);
- (void) printf("Bases: %d",bases);
- scores -= DEATH;
- scoreit();
- if (bases==0) {
- over(); /* game is over */
- }
- (void) sleep(2);
- pos(23,bas.col);
- (void) printf(" ");
- bas.col = 72;
- if ( rand() < 13000 ) bas.col = 1;
- if ( game < 6 )
- {
- pos(23,bas.col);
- ds_obj(7);
- }
- }
- }
- if((bmb[b].row>=19)&&(bmb[b].row<23)&&(barr[bmb[b].row-19][bmb[b].col])) {
-
- /* the bomb has hit a barricade */
-
- pos(bmb[b].row-1,bmb[b].col);
- (void) printf(" \10\12 ");
- barr[bmb[b].row-19][bmb[b].col] = 0;
- bmb[b].row = 0;
- bmb_cnt--;
- continue;
- }
- pos(bmb[b].row-1,bmb[b].col);
- (void) printf(" ");
- if (bmb[b].row==23) {
- bmb_cnt--;
- bmb[b].row = 0;
- }
- else
- (void) printf("\10\12*");
- }
- }
-
- /*
- * ship -- create or advance a mystery ship if desired
- */
-
- ship() {
- int vs_cols = 80;
- if (shp.vel==0) {
- if ((i=rand())<96) {
- /* create a mystery ship */
- if (i<48) {
- shp.vel = 1;
- shp.col = MINCOL;
- }
- else {
- shp.vel = -1;
- shp.col = vs_cols - 8;
- }
- shp.val=90;
- }
- }
- else {
-
- /* update existing mystery ship */
-
- pos(1,shp.col);
- if (game<=3) (void) printf(" <=%d=> ",shp.val/3);
- shp.val--;
- shp.col += shp.vel;
- if (((i=shp.col)>(vs_cols-8))||(i<MINCOL)) {
-
- /* remove ship */
-
- pos(1,shp.col-shp.vel);
- (void) printf(" ");
- shp.vel = 0;
- }
- }
- }
-
- /*
- * alien -- advance the next alien
- */
-
- alien()
- {
- while (1)
- {
- if ((al_num = al_num + 1) >= 55)
- {
- if (al_cnt==0) return; /* check if done */
- flop = 0;
- if (flip) { left = 1 - left;
- flop = 1;
- flip = 0;
- }
- al_num = 0;
- }
- if ((i = al[al_num].row)>0) break;
- }
- if (i>=23)
- {
-
- /* game over, aliens have overrun base */
-
- scores -= OVERUN;
- scoreit();
- over();
- }
-
- if (left) al[al_num].col--;
- else al[al_num].col++;
- if (((j = al[al_num].col)==0)||(j>=(75-slow-((3*level)/2)))) flip = 1;
- pos(i,j);
- if (flop) {
- ds_obj(6);
- i = ++al[al_num].row;
- pos(i,j);
- }
- ds_obj(((j+(i/2))&1) + (2*(al_num/22)));
-
- /* check for contact with a barricade */
-
- if ((al[al_num].row>=19)&&(al[al_num].row<23))
- {
- j=al[al_num].col;
- for (i=3;(i>=-1)&&(j+i>=0);i--)
- barr[al[al_num].row-19][al[al_num].col+i] = 0;
- }
-
- /* check for bomb release */
-
- if ((game==1)||(game==2)) return;
- for (i=al_num-11;i>=0;i -= 11) {
- if (al[i].row!=0) return;
- }
- if ( (al[al_num].col >= (bas.col-spread) ) &&
- (al[al_num].col < (bas.col+3+spread) ) &&
- (al[al_num].row<=BOMB_ROW)) {
- for (i=0;i<bmb_max;i++) {
- if (bmb[i].row==0) {
- bmb[i].row = al[al_num].row;
- bmb[i].col = al[al_num].col + 2;
- bmb_cnt++;
- break;
- }
- }
- }
- return;
- };
-
- /*
- * scoreit -- print current point total
- */
-
- scoreit()
- {
- pos(0,16);
- (void) printf("%d ",scores);
- return;
- }
-
- /*
- * gauntlet -- challenge player to tougher game
- */
-
- gauntlet()
- {
- extern unsigned sleep();
- char *epithet();
-
- clr();
- pos(10,10);
- (void) printf("Congratulations %s ",epithet());
- (void) printf("- you have won at level %d",level++);
- pos(12,10);
- (void) printf("Now let's see how good you are at level %d",level);
- (void) sleep(5);
- }
-
- /*
- * epithet -- choose name for player based upon level
- */
-
- char *epithet()
- {
- static char *name[]={
- "rookie",
- "earthling",
- "space cadet",
- "yeoman",
- "lieutenant",
- "commander",
- "captain",
- "admiral",
- "master assassin"
- };
-
- return((level > 8) ? name[8] : name[level] );
- }
-
- /*
- * over -- game over processing
- */
-
- over() {
- int savgam;
- extern unsigned sleep();
-
- /* display the barricades if they were invisible */
-
- if ( game >= 5 )
- {
- savgam = game;
- game = 3;
- for ( i=0; i<=3; i++)
- {
- pos(i+19,0);
- for ( j=0; j<80; j++)
- if ( barr[i][j] == 1 )
- ds_obj(8);
- else
- (void) printf(" ");
- }
- game = savgam;
- }
-
- /* display the aliens if they were invisible */
-
- if (game>=4) {
- savgam = game;
- game = 3; /* remove the cloak of invisibility */
- for (i=0;i<55;i++) if (al[i].row!=0) {
- pos(al[i].row,al[i].col);
- ds_obj(((al[i].col+(al[i].row/2))&1) + (2*(i/22)));
- }
- game = savgam;
- (void) sleep(5);
- }
-
- /* reset tty */
-
- (void) ioctl(ttyin,TCSETAF,&ttyorig);
-
- /* final output */
-
- loggame();
- clr();
- alhs();
- }
-
- /*
- * loggame -- enter users score into log file
- */
-
- loggame()
- {
- char *ptr;
- char *ctime();
- long dummy = 0;
- long time();
- struct passwd *getpwuid(), *p;
- char uname[10];
- extern char *strcpy();
- FILE *logfile;
-
- if ( (logfile = fopen(LOGFILE,"a")) != NULL )
- {
- dummy = time(&dummy);
- ptr = ctime(&dummy);
- if ( (p = getpwuid(getuid())) == NULL )
- return;
- (void) strcpy(uname,p->pw_name);
- (void) fprintf(logfile,"%.24s %s\t%2u\t%2u\t%d\n",
- ptr,uname,game,level,scores);
- }
- return;
- }
-
- /*
- * alhs -- print alien high scores
- */
-
- alhs()
- {
- struct passwd *getpwuid(), *p;
- char hnam[10];
- extern long lseek();
- extern char *strcpy();
-
- if ((scorefile=open(SCOREFILE,O_RDWR)) == -1)
- {
- (void) printf("aliens: can't open the scorefile\n");
- exit(1);
- }
- (void) printf("Game type\t\tHigh Scores\t\tPlayer");
- (void) read( scorefile, (char *) scorsave, SCORESIZE);
- (void) printf("\n");
-
- /* high score to date processing */
-
- if (scorsave[game-1].hscr < scores) {
- scorsave[game-1].sscr = scorsave[game-1].hscr;
- scorsave[game-1].sid = scorsave[game-1].hid;
- scorsave[game-1].hscr = scores;
- scorsave[game-1].hid = getuid();
- (void) lseek(scorefile,0l,0);
- (void) write(scorefile, (char *) scorsave,SCORESIZE);
- scores=0;
- }
- else if (scorsave[game-1].sscr < scores)
- {
- scorsave[game-1].sscr = scores;
- scorsave[game-1].sid = getuid();
- (void) lseek(scorefile,0l,0);
- (void) write(scorefile, (char *) scorsave,SCORESIZE);
- scores=0;
- }
-
- /* print high scores for all games */
-
- for ( i=0; i<6; i++)
- {
- (void) printf("%5u",i+1);
- (void) printf("\t\t\t%7lu",scorsave[i].hscr);
- if ( (p = getpwuid(scorsave[i].hid)) == NULL )
- (void) printf("\t\t\t ???\n");
- else
- {
- (void) strcpy(hnam,p->pw_name);
- (void) printf("\t\t\t%4s",hnam);
- (void) printf("\n");
- }
- (void) printf("\t\t\t%7lu",scorsave[i].sscr);
- if ( (p = getpwuid(scorsave[i].sid)) == NULL )
- (void) printf("\t\t\t ???\n");
- else
- {
- (void) strcpy(hnam,p->pw_name);
- (void) printf("\t\t\t%4s",hnam);
- (void) printf("\n");
- }
-
- /* print users score if not high score */
-
- if ( (game==(i+1)) && (scores != 0) )
- {
- (void) printf("\t\t\t%7d",scores);
- (void) printf("\t\t\t you\n");
- }
- (void) printf("\n");
- }
- (void) close(scorefile);
- exit(0);
- }